/**
 * Copyright (c) 2018 软唐 All rights reserved.
 * <p>
 * https://www.softtown.cn
 * <p>
 * 版权所有，侵权必究！
 */

package com.softtown.modules.sys.controller;

import com.softtown.common.annotation.LogOperation;
import com.softtown.common.utils.Result;
import com.softtown.common.validator.ValidatorUtils;
import com.softtown.modules.sys.dto.CompComDocAttAddDTO;
import com.softtown.modules.sys.dto.CompComDocAttDTO;
import com.softtown.modules.sys.service.CompComDocAttService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 单据附件controller
 *
 * @author Ding Ya Yong
 * @since 1.0.0
 */
@RestController
@RequestMapping("comp/docAtt")
@Api(tags = "单据附件controller")
public class CompComDocAttController {

    @Resource
    private CompComDocAttService compComDocAttService;

    @PostMapping("deleteDocAttById")
    @ApiOperation("删除附件")
    @LogOperation("删除附件")
    public Result deleteDocAttById(@RequestBody CompComDocAttDTO compComDocAttDTO){
        return compComDocAttService.deleteDocAttById(compComDocAttDTO.getId(), compComDocAttDTO.getCompId());
    }

    @PostMapping("deleteDocAttByUrl")
    @ApiOperation("删除附件")
    @LogOperation("删除附件")
    public Result deleteDocAttByUrl(@RequestBody CompComDocAttDTO compComDocAttDTO){
        return compComDocAttService.deleteDocAttByUrl(compComDocAttDTO.getCompId(),compComDocAttDTO.getDocTypeValue(),compComDocAttDTO.getDocId(),compComDocAttDTO.getAttUrl());
    }

    @PostMapping("addDocAtt")
    @ApiOperation("添加附件数据保存数据库")
    @LogOperation("添加附件数据保存数据库")
    public Result addDocAtt(@RequestBody CompComDocAttAddDTO compComDocAttAddDTO){
        ValidatorUtils.validateEntity(compComDocAttAddDTO);
        return compComDocAttService.addDocAtt(compComDocAttAddDTO);
    }
}